const Koa = require('koa') // 引入Koa
const app = new Koa() // 实例化Koa对象
const Router = require('koa-router') // 引入koa-router
const router = new Router() // 实例化路由对象
const fs = require('fs')
const path = require('path')
// 测试接口
const testRouter = new Router({prefix: '/test'})
fs.readFile(path.join(__dirname, '/data/Test.json'), 'utf8', (err, data) => {
  testRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(testRouter.routes())
// 融达机电
// 首页接口
const rdjdhomeRouter = new Router({prefix: '/rdjd/home'})
fs.readFile(path.join(__dirname, '/data/rdjd/Home.json'), 'utf8', (err, data) => {
  rdjdhomeRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(rdjdhomeRouter.routes())
// 联系我们接口
const rdjdmessageListRouter = new Router({prefix: '/rdjd/messageList'})
fs.readFile(path.join(__dirname, '/data/rdjd/MessageList.json'), 'utf8', (err, data) => {
  rdjdmessageListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(rdjdmessageListRouter.routes())
// 新闻列表接口
const rdjdnewsListRouter = new Router({prefix: '/rdjd/newsList'})
fs.readFile(path.join(__dirname, '/data/rdjd/NewsList.json'), 'utf8', (err, data) => {
  rdjdnewsListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(rdjdnewsListRouter.routes())
// 项目案例列表接口
const rdjdprojectCaseListRouter = new Router({prefix: '/rdjd/projectCaseList'})
fs.readFile(path.join(__dirname, '/data/rdjd/ProjectCaseList.json'), 'utf8', (err, data) => {
  rdjdprojectCaseListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(rdjdprojectCaseListRouter.routes())
// 资质列表接口
const rdjdqualificationsListRouter = new Router({prefix: '/rdjd/qualificationsList'})
fs.readFile(path.join(__dirname, '/data/rdjd/QualificationsList.json'), 'utf8', (err, data) => {
  rdjdqualificationsListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(rdjdqualificationsListRouter.routes())
// 网站架构接口
const rdjdwebSiteArchitectureRouter = new Router({prefix: '/rdjd/webSiteArchitecture'})
fs.readFile(path.join(__dirname, '/data/rdjd/WebSiteArchitecture.json'), 'utf8', (err, data) => {
  rdjdwebSiteArchitectureRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(rdjdwebSiteArchitectureRouter.routes())
// 中南融达
// 首页接口
homeRouter = new Router({prefix: '/znrd/home'})
fs.readFile(path.join(__dirname, '/data/znrd/Home.json'), 'utf8', (err, data) => {
  homeRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(homeRouter.routes())
// 联系我们接口
const znrdmessageListRouter = new Router({prefix: '/znrd/messageList'})
fs.readFile(path.join(__dirname, '/data/znrd/MessageList.json'), 'utf8', (err, data) => {
  znrdmessageListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(znrdmessageListRouter.routes())
// 新闻列表接口
const znrdnewsListRouter = new Router({prefix: '/znrd/newsList'})
fs.readFile(path.join(__dirname, '/data/znrd/NewsList.json'), 'utf8', (err, data) => {
  znrdnewsListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(znrdnewsListRouter.routes())
// 项目案例列表接口
const znrdprojectCaseListRouter = new Router({prefix: '/znrd/projectCaseList'})
fs.readFile(path.join(__dirname, '/data/znrd/ProjectCaseList.json'), 'utf8', (err, data) => {
  znrdprojectCaseListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(znrdprojectCaseListRouter.routes())
// 资质列表接口
const znrdqualificationsListRouter = new Router({prefix: '/znrd/qualificationsList'})
fs.readFile(path.join(__dirname, '/data/znrd/QualificationsList.json'), 'utf8', (err, data) => {
  znrdqualificationsListRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(znrdqualificationsListRouter.routes())
// 网站架构接口
const znrdwebSiteArchitectureRouter = new Router({prefix: '/znrd/webSiteArchitecture'})
fs.readFile(path.join(__dirname, '/data/znrd/WebSiteArchitecture.json'), 'utf8', (err, data) => {
  znrdwebSiteArchitectureRouter.get('/', ctx => {
    ctx.body = data
  })
})
app.use(znrdwebSiteArchitectureRouter.routes())

app.use(router.routes())

app.use(router.allowedMethods())
app.listen(3001, () => {
  console.log('server is starting at port 3001')
})
